package cn.iocoder.yudao.module.famous.doctor.controller.app.patientaudit;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.famous.doctor.controller.admin.patientaudit.vo.*;
import cn.iocoder.yudao.module.famous.doctor.convert.patientaudit.PatientAuditConvert;
import cn.iocoder.yudao.module.famous.doctor.dal.dataobject.patientaudit.PatientAuditDO;
import cn.iocoder.yudao.module.famous.doctor.service.patientaudit.PatientAuditService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 APP - 临床研究患者审批")
@RestController
@RequestMapping("/famous.doctor/patient-audit/app")
@Validated
public class AppPatientAuditController {

    @Resource
    private PatientAuditService patientAuditService;

    @PostMapping("/create")
    @Operation(summary = "创建临床研究患者审批")
    public CommonResult<Integer> createPatientAudit(@Valid @RequestBody PatientAuditCreateReqVO createReqVO) {
        return success(patientAuditService.createPatientAudit(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新临床研究患者审批")
    public CommonResult<Boolean> updatePatientAudit(@Valid @RequestBody PatientAuditUpdateReqVO updateReqVO) {
        patientAuditService.updatePatientAudit(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除临床研究患者审批")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deletePatientAudit(@RequestParam("id") Integer id) {
        patientAuditService.deletePatientAudit(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得临床研究患者审批")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<PatientAuditRespVO> getPatientAudit(@RequestParam("id") Integer id) {
        PatientAuditDO patientAudit = patientAuditService.getPatientAudit(id);
        return success(PatientAuditConvert.INSTANCE.convert(patientAudit));
    }

    @GetMapping("/getUserstate")
    @Operation(summary = "获取 临床研究患者审批---审核状态")
    public CommonResult<PatientAuditRespVO> getUserstate(@RequestParam("clinicId") Long clinicId) {
        PatientAuditDO patientAudit = patientAuditService.getUserstate(clinicId);
        return success(PatientAuditConvert.INSTANCE.convert(patientAudit));
    }
    @GetMapping("/list")
    @Operation(summary = "获得临床研究患者审批列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<PatientAuditRespVO>> getPatientAuditList(@RequestParam("ids") Collection<Integer> ids) {
        List<PatientAuditDO> list = patientAuditService.getPatientAuditList(ids);
        return success(PatientAuditConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得临床研究患者审批分页")
    public CommonResult<PageResult<PatientAuditRespVO>> getPatientAuditPage(@Valid PatientAuditPageReqVO pageVO) {
        PageResult<PatientAuditDO> pageResult = patientAuditService.getPatientAuditPage(pageVO);
        return success(PatientAuditConvert.INSTANCE.convertPage(pageResult));
    }

}
